#!/bin/bash
###SHELLPACK preamble xfsio-bench 0

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargParam	--iterations	XFSIO_ITERATIONS
###SHELLPACK parseargParam	--size		XFSIO_SIZE
###SHELLPACK parseargParam	--testcases	XFSIO_TESTCASES
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

install-depends xfsprogs
###SHELLPACK init_complete

XFSIO_TESTCASES=`echo $XFSIO_TESTCASES | tr ',' ' '`

for TESTCASE in $XFSIO_TESTCASES; do

	# Prepare step
	case $TESTCASE in
	pwrite-single-rewrite-async)
		echo Writing file first, no measurement
		xfs_io -f -c "pwrite 0 $XFSIO_SIZE" $SHELLPACK_DATA/file |
			tee -a $TESTCASE-setup
		;;
	esac

	monitor_pre_hook $LOGDIR_RESULTS $TESTCASE
	###SHELLPACK iteration_begin $XFSIO_ITERATIONS
	case $TESTCASE in
	pwrite-single-async)
		$TIME_CMD -o $LOGDIR_RESULTS/$TESTCASE-time.$ITERATION \
			xfs_io -f -c "pwrite 0 $XFSIO_SIZE" $SHELLPACK_DATA/file |
				tee -a $LOGDIR_RESULTS/$TESTCASE-log.$ITERATION
		rm $SHELLPACK_DATA/file
		sync
		;;
	pwrite-single-rewrite-async)
		$TIME_CMD -o $LOGDIR_RESULTS/$TESTCASE-time.$ITERATION \
			xfs_io -f -c "pwrite 0 $XFSIO_SIZE" $SHELLPACK_DATA/file |
				tee -a $LOGDIR_RESULTS/$TESTCASE-log.$ITERATION
		;;
	*)
		die Unrecognised testcase $TESTCASE
		;;
	esac
	###SHELLPACK iteration_end $XFSIO_ITERATIONS
	rm $SHELLPACK_DATA/file*
	monitor_post_hook $LOGDIR_RESULTS $TESTCASE
done

exit $SHELLPACK_SUCCESS
